package com.bi.autotest;

import com.auto.base.OperateAppium;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebElement;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.PrimitiveIterator;

/**
 * Created by yidian on 2018/3/20.
 */
public class FirstTest {

    private AndroidDriver driver;

    @BeforeClass
    public void setUp() throws MalformedURLException {
        DesiredCapabilities cap = new DesiredCapabilities();

        cap.setCapability(CapabilityType.BROWSER_NAME, "");
        cap.setCapability("platformName", "Android"); //指定测试平台
        cap.setCapability("deviceName", "P101179T04422"); //指定测试机的ID,通过adb命令`adb devices`获取
        cap.setCapability("platformVersion", "6.0");

        //将上面获取到的包名和Activity名设置为值
        cap.setCapability("appPackage", "com.tencent.mm");
        cap.setCapability("appActivity", "com.tencent.mm.ui.LauncherUI");

        //A new session could not be created的解决方法
        cap.setCapability("appWaitActivity","com.tencent.mm.ui.LauncherUI");
        //每次启动时覆盖session，否则第二次后运行会报错不能新建session
        cap.setCapability("sessionOverride", true);

        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
    }

    @Test
    public void exeTest(){
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        AndroidElement ae= (AndroidElement) driver.findElementByName("我");

        ae.click();


        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        driver.findElementByName("收藏").click();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        driver.findElementById("com.tencent.mm:id/b4o").click();
        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        driver.findElementByName("《宜店用户服务协议》").click();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        OperateAppium operateAppium2=new OperateAppium(driver);

        operateAppium2.swipeToUp(3);


      /*  driver.findElementByName("输入您的手机号").sendKeys("15210523000");
        driver.findElementByName("输入验证码").sendKeys("0123");

        driver.findElementByName("确定").click();*/



    }

    @AfterClass
    public void tearDown() throws Exception {
        driver.quit();

    }

}
